home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_c / pclc41.zip / DIR_IO.C < prev    next >
Text File  |  1993-09-21  |  2KB  |  101 lines

  1. /*
  2. **  DIR_IO.C
  3. **
  4. **  Compile with Microsoft C, Borland Turbo C, or MIX Power C.  You may
  5. **  need to modify the following code for your specfic compiler. Some
  6. **  older versions of Microsoft C do not support directory I/O.
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <dos.h>
  12. #include <string.h>
  13.  
  14. #ifndef FALSE
  15. #define FALSE 0
  16. #endif
  17.  
  18. #ifndef TRUE
  19. #define TRUE !FALSE
  20. #endif
  21.  
  22. /*** define compiler specfic includes ***/
  23.  
  24. #ifdef __POWERC
  25. /* MIX Power C compiler */
  26. #define TURBO_OR_POWERC
  27. #include <direct.h>
  28. #endif
  29.  
  30. #ifdef __TURBOC__
  31. /* Borland Turbo C compiler */
  32. #define TURBO_OR_POWERC
  33. #include <dir.h>
  34. #endif
  35.  
  36. #ifdef _MSC_VER
  37. /* Microsoft C compiler */
  38. static struct _find_t DirStruct;
  39. #endif
  40.  
  41. #ifdef TURBO_OR_POWERC
  42. static char DTAbuffer[256];
  43. static struct ffblk DirStruct;
  44. #endif
  45.  
  46. /*** FindFirst() and FindNext() functions ***/
  47.  
  48. int FindFirst(char *FileSpec,char *Buffer)
  49. {
  50. #if _QC
  51.  /* Quick C has no "FindFirst" function */
  52.  strcpy(Buffer,FileSpec);
  53. #endif
  54.  
  55. #ifdef _MSC_VER
  56.  if(_dos_findfirst(FileSpec,_A_NORMAL,&DirStruct)==0)
  57.    {
  58.     strncpy(Buffer,DirStruct.name,13);
  59.     return(TRUE);
  60.    }
  61.  return(FALSE);
  62. #endif
  63.  
  64. #ifdef TURBO_OR_POWERC
  65.  setdta(DTAbuffer);
  66.  if( findfirst(FileSpec,&DirStruct,0)==0)
  67.    {
  68.     strncpy(Buffer,DirStruct.ff_name,13);
  69.     return(TRUE);
  70.    }
  71.  return(FALSE);
  72. #endif
  73. }
  74.  
  75. int FindNext(char *Buffer)
  76. {int Result;
  77.  
  78. #if _QC
  79.  /* Quick C has no "FindNext" function */
  80.  return(FALSE);
  81. #endif
  82.  
  83. #ifdef _MSC_VER
  84. Result = _dos_findnext(&DirStruct);
  85. if(Result==0)
  86.    {
  87.     strncpy(Buffer,DirStruct.name,13);
  88.     return(TRUE);
  89.    }
  90.  return(FALSE);
  91. #endif
  92.  
  93. #ifdef TURBO_OR_POWERC
  94.  if( findnext(&DirStruct)==0 )
  95.    {
  96.     strncpy(Buffer,DirStruct.ff_name,13);
  97.     return(TRUE);
  98.    }
  99.  return(FALSE);
  100. #endif
  101. }